﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using GMap.NET;
using GMap.NET.Projections;

namespace GoogleMapsAPI
{
    class Marker : DrawingArea
    {
        Image markerImage;
        int X = 0;
        int Y = 0;

        public Marker()
        {
            markerImage = Properties.Resources.marker;
            this.Width = 640;
            this.Height = 640;
        }
        public Marker(Image i, Point pos)
        {
            markerImage = i;
            X = pos.X;
            Y = pos.Y;
            Width = 640;
            Height = 640;
        }

        public Marker(Image i, PointLatLng pos, Double Lat, Double Lng, int zoom)
        {
            markerImage = i;
            Width = 640;
            Height = 640;

            MercatorProjection mp = new MercatorProjection();
            Point p = mp.FromLatLngToPixel(pos.Lat - Lat, pos.Lng - Lng, zoom);
            Point temp = mp.FromLatLngToPixel(0, 0, zoom);
            Point deltapos = new Point(temp.X - p.X, temp.Y - p.Y);
            X = Width - deltapos.X;
            Y = Height - deltapos.Y;
        }

        protected override void OnDraw()
        {
            // Sets the images' sizes and positions
            int width = markerImage.Size.Width;
            int height = markerImage.Size.Height;
            Rectangle rect = new Rectangle(X, Y, width, height);

            // Draws the two images
            this.graphics.DrawImage(markerImage, rect);
        }
    }
}
